home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / RENAME.C < prev    next >
C/C++ Source or Header  |  1991-11-21  |  2KB  |  54 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    r e n a m e . c                                                 */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <time.h>
  16.  
  17. /*--------------------------------------------------------------------*/
  18. /*                    UUPC/extended include files                     */
  19. /*--------------------------------------------------------------------*/
  20.  
  21. #include "lib.h"
  22.  
  23. /*--------------------------------------------------------------------*/
  24. /*    R E N A M E                                                     */
  25. /*                                                                    */
  26. /*    Rename a file, creating the target directory if needed          */
  27. /*--------------------------------------------------------------------*/
  28.  
  29. int RENAME(const char *oldname, const char *newname )
  30. {
  31.  
  32.    char *last;
  33.  
  34. /*--------------------------------------------------------------------*/
  35. /*                     Attempt to rename the file                     */
  36. /*--------------------------------------------------------------------*/
  37.  
  38.    if (!rename( oldname, newname )) /* Success?                      */
  39.       return 0;                     /* Yes --> Return to caller      */
  40.  
  41. /*--------------------------------------------------------------------*/
  42. /*      Try rebuilding the directory and THEN renaming the file       */
  43. /*--------------------------------------------------------------------*/
  44.  
  45.    if ((last = strrchr(newname, '/')) != nil(char))
  46.    {
  47.       *last = '\0';
  48.       MKDIR(newname);
  49.       *last = '/';
  50.    }
  51.  
  52.    return rename( oldname, newname );
  53. } /* RENAME */
  54.